package com.lhy.service.impl;

import com.lhy.dao.DepartmentDao;
import com.lhy.domain.Department;
import com.lhy.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 汪
 */
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    DepartmentDao departmentDao;

    @Override
    public List<Department> showAllDepartment() {
        List<Department> departments = departmentDao.showAllDepartment();
        for (Department department : departments) {
            String realName = departmentDao.selectOneByUserId(department.getUserId());
            department.setUserName(realName);
        }
        return departments;
    }

    @Override
    public List<Department> findSomeDepartment(Department department) {
        List<Department> departments=departmentDao.findSomeDepartment(department);
        for (Department department1 : departments) {
            String realName = departmentDao.selectOneByUserId(department1.getUserId());
            department1.setUserName(realName);
        }
        return departments;
    }

    @Override
    public int addDepartment(Department department) {
        return departmentDao.addDepartment(department);
    }

    @Override
    public int deleteDepartment(Integer departId) {
        return departmentDao.deleteDepartment(departId);
    }

    @Override
    public int modifyDepartment(Integer departId,String name,Integer old_departid) {
        return departmentDao.modifyDepartment(departId,name,old_departid);
    }
}
